
from watchdog.observers import Observer
from watchdog.events import *
import time
import gitcode

a = r"H:\Code\python\p_colde"

class MyHandler(FileSystemEventHandler):
    # def on_modified(self, event):
    #     print("文件被修改了 %s " %event.src_path)
    #
    # def on_created(self, event):
    #     print("文件被创建了 %s" % event.src_path)
    # def on_moved(self, event):
    #     print("文件被移动了%s" % event.src_path)
    # def on_deleted(self, event):
    #     print("文件被删除%s" % event.src_path)

    def on_any_event(self, event):
        # if event.src_path =
        to_path = 'H:\Code\python\.idea'
        # res_dir
        fa = re.search(r'H:\\Code\\python\\p_colde\\.git',event.src_path,re.M|re.I);

        tmp = re.search(r'___jb_tmp___',event.src_path,re.M|re.I);
        cach = re.search(r'__pycache__',event.src_path,re.M|re.I);

        if not (fa or tmp or cach):
            gitcode.git_push()

        print("文件发生改动%s" % event.src_path)


if __name__ == "__main__":


    path = a
    event_handler = MyHandler()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()

    try:
        while True:
            time.sleep(1)

    except KeyboardInterrupt:
        observer.stop()
    print("nnnn")

    observer.join()